package br.com.fafica.sisape.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.SwingConstants;
import javax.swing.JTextField;
import javax.swing.JButton;

import br.com.fafica.sisape.control.ControllerHospital;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class TelaHospitalCadastra extends JFrame {

	private JPanel contentPane;
	private JTextField campoNome;
	private JTextField campoCnpj;
	private JTextField campoRua;
	private JTextField campoCidade;
	private JTextField campoTelefone;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TelaClinicaCadastrar frame = new TelaClinicaCadastrar();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public TelaHospitalCadastra() {
		setResizable(false);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBackground(new Color(255, 255, 255));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNome = new JLabel("Nome:");
		lblNome.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNome.setForeground(new Color(0, 0, 128));
		lblNome.setFont(new Font("Tahoma", Font.PLAIN, 12));
		lblNome.setBounds(63, 43, 46, 14);
		contentPane.add(lblNome);
		
		campoNome = new JTextField();
		campoNome.setForeground(new Color(0, 0, 128));
		campoNome.setFont(new Font("Tahoma", Font.PLAIN, 12));
		campoNome.setBounds(116, 41, 224, 20);
		contentPane.add(campoNome);
		campoNome.setColumns(10);
		
		JLabel lblCnpj = new JLabel("Cnpj:");
		lblCnpj.setHorizontalAlignment(SwingConstants.RIGHT);
		lblCnpj.setForeground(new Color(0, 0, 128));
		lblCnpj.setFont(new Font("Tahoma", Font.PLAIN, 12));
		lblCnpj.setBounds(63, 82, 46, 14);
		contentPane.add(lblCnpj);
		
		campoCnpj = new JTextField();
		campoCnpj.setForeground(new Color(0, 0, 128));
		campoCnpj.setFont(new Font("Tahoma", Font.PLAIN, 12));
		campoCnpj.setColumns(10);
		campoCnpj.setBounds(116, 80, 224, 20);
		contentPane.add(campoCnpj);
		
		JLabel lblEndereo = new JLabel("Endere\u00E7o:");
		lblEndereo.setHorizontalAlignment(SwingConstants.RIGHT);
		lblEndereo.setForeground(new Color(0, 0, 128));
		lblEndereo.setFont(new Font("Tahoma", Font.PLAIN, 12));
		lblEndereo.setBounds(30, 125, 79, 14);
		contentPane.add(lblEndereo);
		
		campoRua = new JTextField();
		campoRua.setForeground(new Color(0, 0, 128));
		campoRua.setFont(new Font("Tahoma", Font.PLAIN, 12));
		campoRua.setColumns(10);
		campoRua.setBounds(116, 123, 224, 20);
		contentPane.add(campoRua);
		
		JLabel lblCidade = new JLabel("Cidade:");
		lblCidade.setHorizontalAlignment(SwingConstants.RIGHT);
		lblCidade.setForeground(new Color(0, 0, 128));
		lblCidade.setFont(new Font("Tahoma", Font.PLAIN, 12));
		lblCidade.setBounds(63, 163, 46, 14);
		contentPane.add(lblCidade);
		
		campoCidade = new JTextField();
		campoCidade.setForeground(new Color(0, 0, 128));
		campoCidade.setFont(new Font("Tahoma", Font.PLAIN, 12));
		campoCidade.setColumns(10);
		campoCidade.setBounds(116, 161, 224, 20);
		contentPane.add(campoCidade);
		
		JLabel lblTelefone = new JLabel("Telefone:");
		lblTelefone.setHorizontalAlignment(SwingConstants.RIGHT);
		lblTelefone.setForeground(new Color(0, 0, 128));
		lblTelefone.setFont(new Font("Tahoma", Font.PLAIN, 12));
		lblTelefone.setBounds(30, 204, 79, 14);
		contentPane.add(lblTelefone);
		
		campoTelefone = new JTextField();
		campoTelefone.setForeground(new Color(0, 0, 128));
		campoTelefone.setFont(new Font("Tahoma", Font.PLAIN, 12));
		campoTelefone.setColumns(10);
		campoTelefone.setBounds(116, 202, 111, 20);
		contentPane.add(campoTelefone);
		
		JButton btnNewButton = new JButton("Salvar");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String nome = campoNome.getText();
				String cnpj = campoCnpj.getText();
				String rua = campoRua.getText();
				String cidade = campoCidade.getText();
				String telefone = campoTelefone.getText();
				
				ControllerHospital control = new ControllerHospital();
				control.InserirHospital(nome, rua, cidade, cnpj, telefone);
				dispose();
			}
		});
		btnNewButton.setForeground(new Color(0, 0, 128));
		btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 12));
		btnNewButton.setBounds(294, 207, 99, 30);
		contentPane.add(btnNewButton);
	}
}